package com.ch.chatbot.domain.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ch.chatbot.domain.mapper.QuestionMapper;
import com.ch.chatbot.domain.model.po.QuestionEntity;
import com.ch.chatbot.domain.service.IQuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author chenhao
 * @date 2023-03-22 20:12:22
 * @description
 */
@Service
public class QuestionServiceImpl extends ServiceImpl<QuestionMapper, QuestionEntity> implements IQuestionService {

    @Autowired
    QuestionMapper questionMapper;

    /**
     * 获取多个
     * @param userName
     * @return
     */
    public List<QuestionEntity> queryLastQuestion(String userName) {
        QueryWrapper<QuestionEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_name", userName);
        queryWrapper.orderByDesc("create_time");
        queryWrapper.last("limit 5");
        return questionMapper.selectList(queryWrapper);
    }
}
